package edu.uclmgmu.bacteriosec.aspects.java.io.BOS;

import edu.uclmgmu.bacteriosec.aspects.common.Store;

privileged aspect BufferedOutputStream_NoFlush {

	void around(java.io.BufferedOutputStream caller) : call(void java.io.BufferedOutputStream.flush()) && 
			target(caller) && 
			!cflow(within(BufferedOutputStream_NoFlush)) && !within(edu.uclmgmu.bacteriosec.aspects.common.Store) 
			&& !within(junit.*) {
		String currentJoinPoint = Store.getCurrentjoinPoint();
		String signature=thisJoinPointStaticPart.getSignature().toString();
		if (currentJoinPoint.equals(signature)) {
			int numberOfCallInTurn = Store.getNumberOfCallInTurn(signature);
			int numberOfCurrentCall = Store.getNumberOfCurrentCall(signature);
			Store.updateNumberOfCurrentCall(signature);
			if (numberOfCallInTurn == numberOfCurrentCall) {

			} else {
				proceed(caller);
			}
		} else {
			Store.updateNumberOfCurrentCall(signature);
			proceed(caller);
		}	
	}
}
